<template>
  <a-select :placeholder="placeholder" :default-value="value" @change="handleInput" allowClear>
    <a-select-option v-for="(dbmsSource,index) in dbmsSources" :key="index" :value="dbmsSource.id">
      {{ dbmsSource.sourceName }}
    </a-select-option>
  </a-select>
</template>

<script>
  import {getAction, httpAction, putAction, postAction} from '@/api/manage'

  export default {
    name: "DataSourceSelect",
    props: {
      placeholder: String,
      value: Number,// 1.接收一个 value prop
    },
    data() {
      return {
        dbmsSources: [],
      }
    },
    created() {
      //获取字典数据
      this.initDataSource();
    },
    methods: {
      initDataSource() {
        //根据字典Code, 初始化字典数组
        getAction("/dbms/dbmsDbsource/listAll", "").then((res) => {
          if (res.success) {
            this.dbmsSources = res.result;
          }
        });
      },
      handleInput(val) {
        this.$emit('input', val); // 2.触发 input 事件，并传入新值
      }
    }
  }
</script>

<style scoped>
</style>